﻿using UnityEngine;
using System.Collections;
using System;

public class DowloadPic : MonoBehaviour
{
	public event Action<WWW> DownloadCallback;
	string path1 = "https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xpa1/t31.0-8/10498595_927729300575925_6116907145111484546_o.jpg";
	string path2 = "https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xpa1/t1.0-9/10517483_932324603449728_2122601896307717465_n.jpg";
	string path3 = "https://scontent-b-sjc.xx.fbcdn.net/hphotos-xfp1/t31.0-8/905884_932324716783050_4853892090843264866_o.jpg";
	public void StartGetPicture(int count)
	{
		count = count % 3;
		if (count == 2)
		{
			linkRequest = path1;
		}
		if (count == 1)
		{
			linkRequest = path2;
		}
		if (count == 0)
		{
			linkRequest = path3;
		}
		StartCoroutine(GetPictureCoroutine());
	}
	string linkRequest = "";
	private IEnumerator GetPictureCoroutine()
	{
		Debug.Log("GetPictureCoroutine");
		WWW www = new WWW(linkRequest);
		yield return www;
		if (www.error != null)
		{
			Debug.Log("GetPictureCoroutine www.error");
			yield break;
		}
		if (DownloadCallback!=null)
		{
			DownloadCallback(www);
		}
		DestroyImmediate(this);
	}
}
